/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufrgs.inf.prav.interop.jsf.components;

import java.io.IOException;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.servlet.ServletContext;

/**
 *
 * @author Fernando
 */
public class ImgComponent extends PravBaseComponent{

    public static final String COMPONENT_FAMILY = "PRAV_IMG";
    public static final String COMPONENT_TYPE = "PRAV_IMG";

    //atts
    private String src, alt;    
    //optionl atts
    private String height, ismap, longdesc, usemap, width;

    public ImgComponent(){
        
    }

    @Override
    public void encodeBegin(FacesContext context) throws IOException {
        if (!displayPlataform())
            return;

		ResponseWriter writer =
			context.getResponseWriter();
		writer.startElement("img", this);

        //fix src attribute
//        if (id != null)
//            src = makeReferenceFromItemID(id);
//        else
        src = makeFinalReference(src);

        if (lomId != null)
            src = makeReferenceFromMetadata(lomId);


        String navBarMod = (String)context.
                getExternalContext().getRequestMap().get("barLocModifier");
        if (navBarMod != null)
            src = navBarMod + src;

        //atts
        writer.writeAttribute("src", src, "src");
        writer.writeAttribute("alt", alt, "alt");
        //otional atts
        writer.writeAttribute("height", height, "height");
        writer.writeAttribute("ismap", ismap, "ismap");
        writer.writeAttribute("longdesc", longdesc, "longdesc");
        writer.writeAttribute("usemap", usemap, "usemap");
        writer.writeAttribute("width", width, "width");

        addBaseAttributes(writer);
//        hidePlataformSpecificContent(writer);

        writer.flush();
	}

    @Override
    public void encodeEnd(FacesContext context)
            throws IOException {
        if (!displayPlataform())
            return;
        ResponseWriter writer = context.getResponseWriter();
        writer.endElement("img");
        writer.flush();
    }

    @Override
    public void decode(FacesContext context) {
        return;
    }
    
    // <editor-fold defaultstate="collapsed" desc="Getters and Setters">

    public String getAlt() {
        return alt;
    }

    public void setAlt(String alt) {
        this.alt = alt;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }

    public String getIsmap() {
        return ismap;
    }

    public void setIsmap(String ismap) {
        this.ismap = ismap;
    }

    public String getLongdesc() {
        return longdesc;
    }

    public void setLongdesc(String longdesc) {
        this.longdesc = longdesc;
    }

    public String getSrc() {
        return src;
    }

    public void setSrc(String src) {
        this.src = src;
    }

    public String getUsemap() {
        return usemap;
    }

    public void setUsemap(String usemap) {
        this.usemap = usemap;
    }

    public String getWidth() {
        return width;
    }

    public void setWidth(String width) {
        this.width = width;
    }

    // </editor-fold>


}
